// ignore_for_file: non_constant_identifier_names
import 'package:get/get.dart';
import 'package:sj001/model/revMsgModel.dart';

class ChatMsgItem {
  int user; // 0:AI ,1:用户
  RxString message_id;
  String conversation_id;
  RxList<RevMsgModel> models;
  RxBool isDone;
  RxBool isLike;
  RxInt createAt;
  ChatMsgItem({
    required this.user,
    required this.message_id,
    required this.models,
    required this.isDone,
    required this.conversation_id,
    required this.isLike,
    required this.createAt,
  });

  Map<String, dynamic> toJson() {
    return {
      "message_id": message_id.value,
      "models": models.value.map((e) => e.toJson()).toList(),
      'isDone': isDone.value,
      'conversation_id': conversation_id,
      'user': user,
      'isLike': isLike.value,
      'createAt': createAt.value,
    };
  }

  factory ChatMsgItem.fromJson(Map<String, dynamic> json) {
    List<RevMsgModel> list = [];

    if (json['models'] != null) {
      for (var e in json['models']!) {
        list.add(RevMsgModel.fromJson(e));
      }
    }

    return ChatMsgItem(
      message_id: (json["message_id"] ?? '').obs,
      isDone: (json["isDone"] ?? true).obs,
      isLike: (json["isLike"] ?? false).obs,
      models: list.obs,
      user: json["user"],
      createAt: (json["createAt"]??'').obs,
      conversation_id: json["conversation_id"],
    );
  }
//
}
